/*
 *
 *  Copyright (C) 2010 Tal Eisenberg
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package tal.drivechain.variable.types;

import tal.drivechain.matchers.ValueMatcher;
import tal.drivechain.variable.SetProperty;
import tal.drivechain.variable.SetProperty.Flag;
import tal.drivechain.variable.expressions.CustomExpression;
import tal.drivechain.variable.expressions.SetPropertyExpression;

/**
 *
 * @author Main
 */
public class SetPropertyType extends DataType {
    public SetPropertyType() {
        super("prop", SetProperty.class, 13);
    }

    @Override
    public boolean isValue(String def) {
        try {
            this.parseValue(def);
            return true;
        } catch (IllegalArgumentException ie) {
            //find out if the cause is an error in SetProperty
/*            for (StackTraceElement s : ie.getStackTrace()) {
                if (s.getClassName().endsWith(".SetProperty"))
                    return true;
            }*/
            return false;
        }
    }

    @Override
    public Object parseValue(String value) throws IllegalArgumentException {
        //[name]/[flag]{value, value, value}
        Object[] params = SetProperty.parseSetProperty(value);
        return new SetProperty((String)params[0], (String[])params[1], (Flag)params[2]);
    }

    @Override
    public CustomExpression createExpression(String value) throws IllegalArgumentException {
        return new SetPropertyExpression(value, this);
    }

    @Override
    public ValueMatcher createValueMatcher() throws IllegalArgumentException {
        throw new IllegalArgumentException("Value matchers are not supported for prop variables.");
    }
}
